<template>
  <view class="noctice-container">
    <view
      v-for="item in noticeList"
      :key="item.id"
      class="notice-list-item default-box-shadow"
      @click="handleNotice(item.id)">
      <view class="notice-title">
        <view class="title-text text-overflow">{{ item.title }}</view>
        <view class="title-time">{{ item.created_at }}</view>
      </view>
      <view class="notice-content">
        <u-parse :html="item.content"></u-parse>
      </view>
      <view class="list-footer">
        <text>查看详情</text>
        <u-icon class="arrow-right" color="#56d39d" name="arrow-right"></u-icon>
      </view>
    </view>
  </view>
</template>

<script>
  import { questionListByBusinessId } from '@/api/applet';
  import { parseTime } from '@/utils/parseTime';
  export default {
    data() {
      return {
        noticeList: [],
      }
    },
    mounted() {
      this.getNoticeList();
    },
    methods: {
      // 获取公告
			getNoticeList() {
				questionListByBusinessId({
					type: '2'
				}).then(result => {
					if (result && result.data && result.data.length > 0) {
            let list = result.data;
            list.forEach(item => {
              item.created_at = parseTime(new Date(item.created_at), '{m}-{d} {h}:{m}');
            })
            this.noticeList = list;
          }
				})
			},

      // 点击公告
      async handleNotice(id) {
        uni.navigateTo({
          url: `/pages/customer/noticeDetail?id=${id}`
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  page{
    background-color: #f5f5f5;
  }
  .noctice-container{
    padding: 32rpx;

    .notice-list-item{
      padding: 24rpx 24rpx 12rpx 24rpx;
      border-radius: 16rpx;
      margin-bottom: 24rpx;

      .notice-title{
        display: flex;
        align-items: center;
        margin-bottom: 32rpx;

        .title-text{
          flex: 1;
          font-size: 32rpx;
          color: #333;
          height: 40rpx;
          font-weight: 500;
        }

        .title-time{
          width: 160rpx;
          font-size: 24rpx;
          text-align: right;
        }
      }

      .notice-content{
        height: 110rpx;
        margin-bottom: 24rpx;
        overflow: hidden;
      }
    }

    .list-footer{
      border-top: 2rpx solid #eaeaea;
      height: 80rpx;
      line-height: 80rpx;
      position: relative;
      color: $uni-color-primary;

      .arrow-right{
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        margin: auto;
        width: 40rpx;
        height: 20rpx;
        line-height: 40rpx;
      }
    }
  }
</style>
